#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <pwd.h>

#define ERR_EXIT(m) 
    do 
    { 
        perror(m); 
        exit(EXIT_FAILURE); 
    } while(0)

int main(void)
{
    uid_t uid;
    struct passwd *pw;
    uid = getuid();
    printf("current user id :%d\n",uid);
    if((pw = getpwuid(uid)) == NULL)
        ERR_EXIT("getpwuid error");
    printf("username:%s\n",pw->pw_name);
    printf("user passwd:%s\n",pw->pw_passwd);
    printf("user ID:%d\n",pw->pw_uid);
    printf("group ID:%d\n",pw->pw_gid);
    //printf("real name:%s\n",pw->pw_gecos);
    printf("home directory:%s\n",pw->pw_dir);
    printf("shell program:%s\n",pw->pw_shell);
    return 0;
}
